<html>
<head><meta charset="utf-8"><title>Why match return () instead of MyEnum ? · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Why.20match.20return.20().20instead.20of.20MyEnum.20.3F.html">Why match return () instead of MyEnum ?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="208956886"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Why%20match%20return%20%28%29%20instead%20of%20MyEnum%20%3F/near/208956886" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nelson nunes <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Why.20match.20return.20().20instead.20of.20MyEnum.20.3F.html#208956886">(Sep 03 2020 at 12:11)</a>:</h4>
<p>Hi newbie here, i have this code :</p>
<div class="codehilite"><pre><span></span><code>fn get_verb_path(method: &amp;&amp;str) -&gt; Http_method {
    let path = method.split_whitespace().collect::&lt;Vec&lt;&amp;str&gt;&gt;()[1];
    match method.split_whitespace().collect::&lt;Vec&lt;&amp;str&gt;&gt;()[0]{
        &quot;GET&quot;  =&gt; Http_method::GET(path.to_string(), false),
        &quot;POST&quot; =&gt; Http_method::POST(path.to_string(), false),
        _      =&gt; Http_method::OTHER(path.to_string(), false),
    }
}

fn read_content(content: &amp;str) -&gt; Http_method {
    match content.split(&quot;\n&quot;).collect::&lt;Vec&lt;&amp;str&gt;&gt;().as_slice().get(0) {
        Some(r) =&gt; get_verb_path(r),
        None =&gt; Http_method::OTHER(String::new(), false),
    };
}
</code></pre></div>


<p>And error :</p>
<div class="codehilite"><pre><span></span><code>80 | fn read_content(content: &amp;str) -&gt; Http_method {
   |    ------------                   ^^^^^^^^^^^ expected enum `Http_method`, found `()`
</code></pre></div>


<p>i dont understand why it doesn't return good type.<br>
thanks</p>



<a name="208956978"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Why%20match%20return%20%28%29%20instead%20of%20MyEnum%20%3F/near/208956978" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Why.20match.20return.20().20instead.20of.20MyEnum.20.3F.html#208956978">(Sep 03 2020 at 12:12)</a>:</h4>
<p>You have a trailing <code>;</code> at the end of <code>read_content</code>. (<code>};</code>)</p>



<a name="208957049"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Why%20match%20return%20%28%29%20instead%20of%20MyEnum%20%3F/near/208957049" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nelson nunes <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Why.20match.20return.20().20instead.20of.20MyEnum.20.3F.html#208957049">(Sep 03 2020 at 12:13)</a>:</h4>
<p><span class="user-mention silent" data-user-id="133247">bjorn3</span> <a href="#narrow/stream/122651-general/topic/Why.20match.20return.20().20instead.20of.20MyEnum.20.3F/near/208956978">said</a>:</p>
<blockquote>
<p>You have a trailing <code>;</code> at the end of <code>read_content</code>. (<code>};</code>)</p>
</blockquote>
<p>Whatttttttttt.<br>
It compile now :)<br>
Thanks a lot</p>



<a name="208957182"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Why%20match%20return%20%28%29%20instead%20of%20MyEnum%20%3F/near/208957182" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Why.20match.20return.20().20instead.20of.20MyEnum.20.3F.html#208957182">(Sep 03 2020 at 12:14)</a>:</h4>
<p>I also make that mistake sometimes. I thought the error message does suggest removing the <code>;</code> though.</p>



<a name="208989722"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Why%20match%20return%20%28%29%20instead%20of%20MyEnum%20%3F/near/208989722" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> yodal <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Why.20match.20return.20().20instead.20of.20MyEnum.20.3F.html#208989722">(Sep 03 2020 at 15:59)</a>:</h4>
<p>I also remember the suggestion. I wonder if rustc simply couldn't figure it out here or if the suggestion regressed</p>



<a name="208989891"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Why%20match%20return%20%28%29%20instead%20of%20MyEnum%20%3F/near/208989891" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Why.20match.20return.20().20instead.20of.20MyEnum.20.3F.html#208989891">(Sep 03 2020 at 16:00)</a>:</h4>
<p>No way to tell without having a self-contained example</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>